<?php
/**
 * Created by PhpStorm.
 * User: 小瓶子
 * Date: 2018/11/8
 * Time: 16:10
 */
namespace app\home\controller;
use app\home\model\Merchant;
use think\Controller;
use think\Request;

class Merlogin extends Controller
{
    public function index()
    {//渲染注册模板
        return $this->fetch("Merlogin/merchant");
    }

    public function merchant_add()
    {//商家注册
        $request = Request::instance();
        $data = $request->post();
        $img = $this->upload('merchant_logo');
        $data['merchant_logo'] = 'uploads/'.$img;
        $data["addtime"]=time();
        $model = new Merchant();
        $res = $model->insert('shop_merchant',$data);
        if ($res){
            $this->redirect('home/Merlogin/deng');
        }else{
            $this->error("商家注册失败");
        }
    }

    public function upload($merchant_logo)
    {//上传商家logo
        $file = request()->file($merchant_logo);
        $info = $file->move(ROOT_PATH.'public'.DS.'uploads');
        if ($info){
            return $info->getSaveName();
        }else{
            return $file->getError();
        }
    }

    public function deng()
    {//渲染商家登陆模板
        return $this->fetch("Merlogin/deng");
    }

    public function deng1()
    {//商家登陆
        $request = Request::instance();
        $data=$request->post();
        $model = new Merchant();
        $res = $model ->show('shop_merchant',$data);

        if ($res){
            $this->redirect('home/Merlogin/index');
        }else{
            $this->error("用户名或密码错误");
        }

    }
}